
<template>
  <el-form>
    <el-form-item
      v-show="radionItem_A.length != 0"
      label-width="120px"
      label="请选择甲端节点："
    >
      <el-radio-group v-model="taskId">
        <el-radio
          v-for="item in radionItem_A"
          :label="item.taskId"
          :key="item.taskId"
          :value="item.taskId"
          >{{ item.nodeName }}</el-radio
        >
      </el-radio-group>
    </el-form-item>

    <el-form-item
      v-show="radionItem_B.length != 0"
      label-width="120px"
      label="请选择乙端节点："
    >
      <el-radio-group v-model="taskId">
        <el-radio
          v-for="item in radionItem_B"
          :label="item.taskId"
          :key="item.taskId"
          :value="item.taskId"
          >{{ item.nodeName }}</el-radio
        >
      </el-radio-group>
    </el-form-item>

    <el-form-item
      v-show="radionItem_C.length != 0"
      label-width="120px"
      label="其他节点："
    >
      <el-radio-group v-model="taskId">
        <el-radio
          v-for="item in radionItem_C"
          :label="item.taskId"
          :key="item.taskId"
          :value="item.taskId"
          >{{ item.nodeName }}</el-radio
        >
      </el-radio-group>
    </el-form-item>

    <el-form-item class="btnDir">
      <el-button @click="onSubmit">确 定</el-button>
      <el-button @click="onCancel">取 消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import requestUtil from "@/utils/requestEnc";
import CustOrderService from "@/api/order/CustOrderService";
import { mapState } from "vuex";
export default {
  components: {
    requestUtil,
    CustOrderService,
  },
  computed: {
    ...mapState("orders", ["orderItemList"]),
    ...mapState("user", ["user"]),
  },

  async mounted() {
    //初始方法，查询任务
    
    

    this.getNodeList();
  },
  watch: {},
  props: {
    ODKInfo: {
      type: Object,
      default: () => {
        return {};
      },
    },
    CTOInfo: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      orderTaskIds: "",
      radionItem: [],
      orderTask: {},
      orderItemIds: "",
      taskId: "",
      taskIds: [],
      //甲端节点
      radionItem_A: [],
      //乙端节点
      radionItem_B: [],
      //其他
      radionItem_C: [],
    };
  },

  methods: {
    onCancel() {
      this.$emit("update:show", false);
    },
    async onSubmit() {

      var itemA = this.radionItem_A.filter((item) => {return item.taskId = this.taskId});
      var itemB = this.radionItem_B.filter((item) => {return item.taskId = this.taskId});
      var itemC = this.radionItem_C.filter((item) => {return item.taskId = this.taskId});
      var nodeName = "";
      if(itemA.length > 0){
        nodeName = itemA.nodeName;
      }else if(itemB.length > 0){
        nodeName = itemB.nodeName;
      }else if(itemC.length > 0){
        nodeName = itemC.nodeName;
      }

      //跳转到资源填报页面
      var content = "zfhs";
      var taskId = this.taskId;
      

      sessionStorage.setItem("proName", "zfhs10450");
    
  let ppmCondition = {
      offerId: this.CTOInfo[0].prodOfferId,
      productId: this.CTOInfo[0].prodId,
      prodName: this.CTOInfo[0].offerName,
      serviceOfferId: "-1", //新装所有产品固定值
      modType: "50200003", //新装所有产品固定值
      //optionId: "TACHE00050001", //新装所有产品固定值
      optionId: taskId,
    };
    
    sessionStorage.setItem("ppmCondition", JSON.stringify(ppmCondition));


      var orderItemIds = "";

      for (var i = 0; i < this.CTOInfo.length; i++) {
        if (i == 0) {
          orderItemIds += this.CTOInfo[i].orderItemId;
        } else {
          orderItemIds += "," + this.CTOInfo[i].orderItemId;
        }
      }


        sessionStorage.setItem("cacheInfo", JSON.stringify({
            productId: this.CTOInfo[0].prodId,
            taskId:taskId,
            OrgId:this.user.orgId,
            serviceOfferId:this.CTOInfo[0].offerId,
            orderItemIds:orderItemIds
        }));

      
      

      this.$emit("changeWindow", this.taskId, content,nodeName);
    },
    async getNodeList() {
      // this.aaa();

      var scopeInfos = [];
      scopeInfos.push({ scope: "orderTasks" });
      var custSoNumber = this.CTOInfo[0].custSoNumber;
      var batchNbr = this.CTOInfo[0].batchNbr;
      var custId = this.CTOInfo[0].custId;

      var orderItemIds = this.ODKInfo.orderItemIds;
      const res = await CustOrderService.qryCustomerOrderDetail({
        custSoNumber,
        batchNbr,
        orderItemIds,
        custId,
        scopeInfos,
      });
      

      //taskid集合
      if (res.orderDetails.length > 0) {
        var orderTaskIds = "";
        for (var i = 0; i < res.orderDetails.length; i++) {
          var orderTasks = res.orderDetails[i]["orderTasks"];
          for (var j = 0; j < orderTasks.length; j++) {
            //查询节点报文拼接taskIds,
            if (i == 0 && j == 0) {
              orderTaskIds += orderTasks[j].taskId;
            } else {
              orderTaskIds += "," + orderTasks[j].taskId;
            }
          }
        }
        this.orderTaskIds = orderTaskIds;
        
      }

      var reqMap = {
        tacheId: "TACHE0005",
        orderItemSeqs: this.CTOInfo[0].orderItemSeq,
        //taskIds: "TACHE00040001",
        taskIds: this.orderTaskIds,
        fCode: "",
        custId: this.CTOInfo[0].custId,
        custSoNumber: this.CTOInfo[0].custSoNumber,
        staffId: this.user.staffId,
        orgId: this.user.orgId,
      };

      var result = await CustOrderService.loadNodeBatch(reqMap);
      
      
      this.radionItem = result.meta;

      if (this.radionItem.length > 0) {
        for (var i = 0; i < this.radionItem.length; i++) {
          var taskid_temp = this.radionItem[i].taskId;
          //甲端节点
          if (taskid_temp == "TACHE00050001") {
            this.radionItem_A.push(this.radionItem[i]);
          } else {
            //乙端节点
            if (taskid_temp == "TACHE00050002") {
              this.radionItem_B.push(this.radionItem[i]);
            } else {
              this.radionItem_C.push(this.radionItem[i]);
            }
          }
        }
      } else {
        this.$confirm("无可选择节点", "提示", {
          confirmButtonText: "确定",
          showCancelButton: false,
          type: "warn",
          center: true,
        });
        this.$emit("close");
      }
      
      
      
    },

    // async aaa() {
    //   var scopeInfos = [];
    //   scopeInfos.push({ scope: "orderTasks" });
    //   var custSoNumber = this.CTOInfo[0].custSoNumber;
    //   var batchNbr = this.CTOInfo[0].batchNbr;
    //   var custId = this.CTOInfo[0].custId;

    //   var orderItemIds = this.ODKInfo.orderItemIds;
    //   const result = await CustOrderService.qryCustomerOrderDetail({
    //     custSoNumber,
    //     batchNbr,
    //     orderItemIds,
    //     custId,
    //     scopeInfos,
    //   });
    //   

    //   //taskid集合
    //   if (result.orderDetails.length > 0) {
    //     var orderTaskIds = "";
    //     for (var i = 0; i < result.orderDetails.length; i++) {
    //       var orderTasks = result.orderDetails[i]["orderTasks"];
    //       for (var j = 0; j < orderTasks.length; j++) {
    //         //查询节点报文拼接taskIds,
    //         if (i == 0 && j == 0) {
    //           orderTaskIds += orderTasks[j].taskId;
    //         } else {
    //           orderTaskIds += "," + orderTasks[j].taskId;
    //         }
    //       }
    //     }
    //     this.orderTaskIds = orderTaskIds;
    //     
    //   }
    // },
  },
};
</script>

<style>
.el-form--inline .el-form-item {
  display: inline-flex;
  margin-right: 0.1rem;
  vertical-align: top;
  width: 42%;
}

.el-form-item__label {
  width: 94px;
}
.btnDir {
  margin-left: 36%;
  margin-top: 19px;
}
::v-deep .el-radio-group input {
  border-left: 0;
}

::v-deep .el-radio-group {
  display: block;
  line-height: 23px;
  white-space: normal;
  margin-right: 0;
}
</style>

